package com.tomcat;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * @Author YongQiang
 * @Date 2021/4/15 16:26
 * @Version 1.0
 */
public class ServerTest {
    public static void main(String[] args) throws Exception {
        Socket socket = new Socket("127.0.0.1", 8003);
        OutputStream os = socket.getOutputStream();
        boolean autoflush = true;
        PrintWriter out = new PrintWriter(
                socket.getOutputStream(), autoflush);
        BufferedReader in = new BufferedReader(
                new InputStreamReader(socket.getInputStream()));
// send an HTTP request to the web server
        out.println("GET /ordws/YzdServlet HTTP/1.1");
        out.println("Host: localhost:8003");
        out.println("Connection: Close");
        out.println();
// read the response
        boolean loop = true;
        StringBuffer sb = new StringBuffer(8096);
        while (loop) {
            if ( in.ready() ) {
                int i=0;
                while (i!=-1) {
                    i = in.read();
                    sb.append((char) i);
                }
                loop = false;
            }
            Thread.sleep(5000);
        }
// display the response to the out console
        System.out.println(sb.toString());
        socket.close();
    }
}
